package pl.druminski.robinhood.model;

import java.net.InetSocketAddress;
import java.net.Proxy;
import javax.swing.table.AbstractTableModel;

/**
 * @author Łukasz Drumiński
 * 
 */
public class ProxyTableModel extends AbstractTableModel
{
    private Data data;
    private int columnCount = 3;

    public ProxyTableModel(Data data)
    {
        this.data = data;
    }

    public int getRowCount()
    {
        return data.proxyList.size();
    }

    public int getColumnCount()
    {
        return columnCount;
    }

    public Object getValueAt(int rowIndex, int columnIndex)
    {
        Proxy proxy = data.proxyList.get(rowIndex);
        Object obj=null;
        InetSocketAddress address = (InetSocketAddress) proxy.address();

        switch (columnIndex)
        {
            case 0: obj = address.getAddress().getHostAddress(); break;
            case 1: obj = address.getPort(); break;
            case 2: obj = proxy.type(); break;
        }

        return obj;
    }

}
